fix some readability-implict-bool-conversion tidy warnings (#1072)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 23 Apr 2023 20:41:29 +0000 (14:41 -0600)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 20:41:29 +0000 (14:41 -0600)
* fix some readability-implicit-bool-conversion

warnings from clang-tidy

* another implicit bool

* fix tidy modernize-use-auto

* fix google-readability-namespace-comments

13 files changed:
defs.h
discard.cc
garmin_txt.cc
igc.cc
igc.h
lowranceusr.cc
lowranceusr.h
main.cc
src/core/codecdevice.cc
src/core/codecdevice.h
util.cc
util_crc.cc
waypt.cc

diff --git a/defs.h b/defs.h
index b01100b7e1c4479265b4088a11e993608c84bf38..f2e67f490218dcdb2c080bb1bd0db99bc49a750c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -163,14 +163,14 @@ enum gpsdata_type {
 #define        doing_posn ((global_opts.masked_objective & POSNDATAMASK) == POSNDATAMASK)
 
 struct global_options {
-  int synthesize_shortnames;
   int debug_level;
   gpsdata_type objective;
   unsigned int masked_objective;
   int verbose_status;  /* set by GUI wrappers for status */
-  int smart_icons;
-  int smart_names;
   inifile_t* inifile;
+  bool synthesize_shortnames;
+  bool smart_icons;
+  bool smart_names;
 };
 
 extern global_options global_opts;
@@ -535,7 +535,7 @@ void waypt_status_disp(int total_ct, int myct);
 //void waypt_disp_all(waypt_cb); /* template */
 //void waypt_disp_session(const session_t* se, waypt_cb cb); /* template */
 void waypt_init_bounds(bounds* bounds);
-int waypt_bounds_valid(bounds* bounds);
+bool waypt_bounds_valid(bounds* bounds);
 void waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp);
 void waypt_compute_bounds(bounds* bounds);
 Waypoint* find_waypt_by_name(const QString& name);
index 7c55a5d9afbb0f311da1a3ed1c3fa289c48679db..249d66a01ce0de1b6116c5bb897b8022c02e5e59 100644 (file)
  */
 void DiscardFilter::fix_process_wpt(const Waypoint* wpt)
 {
-  int del = 0;
-  int delh = 0;
-  int delv = 0;
+  bool del = false;
+  bool delh = false;
+  bool delv = false;
 
   auto* waypointp = const_cast<Waypoint*>(wpt);
 
   if ((hdopf >= 0.0) && (waypointp->hdop > hdopf)) {
-    delh = 1;
+    delh = true;
   }
   if ((vdopf >= 0.0) && (waypointp->vdop > vdopf)) {
-    delv = 1;
+    delv = true;
   }
 
   if (andopt) {
@@ -57,36 +57,36 @@ void DiscardFilter::fix_process_wpt(const Waypoint* wpt)
   }
 
   if ((satpf >= 0) && (waypointp->sat < satpf)) {
-    del = 1;
+    del = true;
   }
 
   if ((fixnoneopt) && (waypointp->fix == fix_none)) {
-    del = 1;
+    del = true;
   }
 
   if ((fixunknownopt) && (waypointp->fix == fix_unknown)) {
-    del = 1;
+    del = true;
   }
 
   if ((eleminopt) && (waypointp->altitude < eleminpf)) {
-    del = 1;
+    del = true;
   }
 
   if ((elemaxopt) && (waypointp->altitude > elemaxpf)) {
-    del = 1;
+    del = true;
   }
 
   if (nameopt && name_regex.match(waypointp->shortname).hasMatch()) {
-    del = 1;
+    del = true;
   }
   if (descopt && desc_regex.match(waypointp->description).hasMatch()) {
-    del = 1;
+    del = true;
   }
   if (cmtopt && cmt_regex.match(waypointp->notes).hasMatch()) {
-    del = 1;
+    del = true;
   }
   if (iconopt && icon_regex.match(waypointp->icon_descr).hasMatch()) {
-    del = 1;
+    del = true;
   }
 
   if (del) {
index 415a48a818807f94502fd6bc290044e62d333ff2..9146aa6dec083c36b30be557d3016aacff59106e 100644 (file)
@@ -363,7 +363,7 @@ print_position(const Waypoint* wpt)
 }
 
 static void
-print_date_and_time(const time_t time, const int time_only)
+print_date_and_time(const time_t time, const bool time_only)
 {
   std::tm tm{};
   char tbuf[32];
@@ -429,7 +429,7 @@ print_course(const Waypoint* A, const Waypoint* B)          /* seems to be okay */
 }
 
 static void
-print_distance(const double distance, const int no_scale, const int with_tab, const int decis)
+print_distance(const double distance, const bool no_scale, const bool with_tab, const int decis)
 {
   double dist = distance;
 
@@ -561,19 +561,19 @@ write_waypt(const Waypoint* wpt)
   print_position(wpt);
 
   if IS_VALID_ALT(wpt->altitude) {
-    print_distance(wpt->altitude, 1, 0, 0);
+    print_distance(wpt->altitude, true, false, 0);
   }
   *fout << "\t";
 
   double x = wpt->depth_value_or(unknown_alt);
   if (x != unknown_alt) {
-    print_distance(x, 1, 0, 1);
+    print_distance(x, true, false, 1);
   }
   *fout << "\t";
 
   x = wpt->proximity_value_or(unknown_alt);
   if (x != unknown_alt) {
-    print_distance(x, 0, 0, 0);
+    print_distance(x, false, false, 0);
   }
   *fout << "\t";
 
@@ -596,7 +596,7 @@ write_waypt(const Waypoint* wpt)
   print_string("%s\t", garmin_fs_t::get_state(gmsd, ""));
   const char* country = gt_get_icao_country(garmin_fs_t::get_cc(gmsd, ""));
   print_string("%s\t", (country != nullptr) ? country : "");
-  print_date_and_time(wpt->GetCreationTime().toTime_t(), 0);
+  print_date_and_time(wpt->GetCreationTime().toTime_t(), false);
   if (wpt->HasUrlLink()) {
     UrlLink l = wpt->GetUrlLink();
     print_string("%s\t", l.url_);
@@ -623,7 +623,7 @@ route_disp_hdr_cb(const route_head* rte)
     *fout << QString::asprintf("\r\n\r\nHeader\t%s\r\n", headers[route_header]);
   }
   print_string("\r\nRoute\t%s\t", rte->rte_name);
-  print_distance(cur_info->length, 0, 1, 0);
+  print_distance(cur_info->length, false, true, 0);
   print_course(cur_info->first_wpt, cur_info->last_wpt);
   *fout << QString::asprintf("\t%d waypoints\t", cur_info->count);
   if (rte->rte_urls.HasUrlLink()) {
@@ -650,11 +650,11 @@ route_disp_wpt_cb(const Waypoint* wpt)
   if (prev != nullptr) {
     double dist = waypt_distance_ex(prev, wpt);
     cur_info->total += dist;
-    print_distance(cur_info->total, 0, 1, 0);
-    print_distance(dist, 0, 1, 0);
+    print_distance(cur_info->total, false, true, 0);
+    print_distance(dist, false, true, 0);
     print_course(prev, wpt);
   } else {
-    print_distance(0, 1, 0, 0);
+    print_distance(0, true, false, 0);
   }
 
   *fout << "\r\n";
@@ -677,9 +677,9 @@ track_disp_hdr_cb(const route_head* track)
     *fout << QString::asprintf("\r\n\r\nHeader\t%s\r\n", headers[track_header]);
   }
   print_string("\r\nTrack\t%s\t", track->rte_name);
-  print_date_and_time(cur_info->start, 0);
-  print_date_and_time(cur_info->time, 1);
-  print_distance(cur_info->length, 0, 1, 0);
+  print_date_and_time(cur_info->start, false);
+  print_date_and_time(cur_info->time, true);
+  print_distance(cur_info->length, false, true, 0);
   print_speed(&cur_info->length, &cur_info->time);
   if (track->rte_urls.HasUrlLink()) {
     print_string("%s", track->rte_urls.GetUrlLink().url_);
@@ -705,15 +705,15 @@ track_disp_wpt_cb(const Waypoint* wpt)
   *fout << "Trackpoint\t";
 
   print_position(wpt);
-  print_date_and_time(wpt->GetCreationTime().toTime_t(), 0);
+  print_date_and_time(wpt->GetCreationTime().toTime_t(), false);
   if IS_VALID_ALT(wpt->altitude) {
-    print_distance(wpt->altitude, 1, 0, 0);
+    print_distance(wpt->altitude, true, false, 0);
   }
 
   *fout << "\t";
   double depth = wpt->depth_value_or(unknown_alt);
   if (depth != unknown_alt) {
-    print_distance(depth, 1, 0, 1);
+    print_distance(depth, true, false, 1);
   }
 
   if (prev != nullptr) {
@@ -725,8 +725,8 @@ track_disp_wpt_cb(const Waypoint* wpt)
     }
     *fout << "\t";
     dist = waypt_distance_ex(prev, wpt);
-    print_distance(dist, 0, 1, 0);
-    print_date_and_time(delta, 1);
+    print_distance(dist, false, true, 0);
+    print_date_and_time(delta, true);
     print_speed(&dist, &delta);
     print_course(prev, wpt);
   }
diff --git a/igc.cc b/igc.cc
index 3aeecabfa380c61888f2b6260d3e333bc4383a7e..1910f291548e57ab91bc7e1b136ddd8f54adf27c 100644 (file)
--- a/igc.cc
+++ b/igc.cc
@@ -69,9 +69,9 @@
  * @retval  1  The coordinates are approximately equal
  * @retval  0  The coordinates are significantly different
  */
-unsigned char IgcFormat::coords_match(double lat1, double lon1, double lat2, double lon2)
+bool IgcFormat::coords_match(double lat1, double lon1, double lat2, double lon2)
 {
-  return (fabs(lat1 - lat2) < 0.0001 && fabs(lon1 - lon2) < 0.0001) ? 1 : 0;
+  return (fabs(lat1 - lat2) < 0.0001 && fabs(lon1 - lon2) < 0.0001);
 }
 
 /*************************************************************************************************
diff --git a/igc.h b/igc.h
index dec27b12e3d7863e697ce6ea4186e9b706cbf0d1..8646c1a1075dbd588e501b3501807adb6d3cc733 100644 (file)
--- a/igc.h
+++ b/igc.h
@@ -236,7 +236,7 @@ private:
 
   /* Member Functions */
 
-  static unsigned char coords_match(double, double, double, double);
+  static bool coords_match(double, double, double, double);
   igc_rec_type_t get_record(char**) const;
   void detect_pres_track(const route_head*);
   void detect_gnss_track(const route_head*);
index 79b74587d3d93f38589ce248bcb99c120baa4f2c..89a61585b99b22896f49135b5816ef1f39648d22 100644 (file)
@@ -122,7 +122,7 @@ extern WaypointList* global_waypoint_list;
 /* below couple of functions mostly borrowed from raymarine.c */
 
 /* make waypoint shortnames unique */
-char
+bool
 LowranceusrFormat::same_points(const Waypoint* A, const Waypoint* B)
 {
   return ( /* !!! We are case-sensitive !!! */
index 605c12bd505760c2c318ee5e5ea9449a2f27e1b3..6013fdb279ff2c14a9fdcd2a6032b1dd373de67c 100644 (file)
@@ -384,7 +384,7 @@ private:
 
   /* Member Functions */
 
-  static char same_points(const Waypoint*, const Waypoint*);
+  static bool same_points(const Waypoint*, const Waypoint*);
   void register_waypt(const Waypoint*) const;
   static const Waypoint* lowranceusr4_find_waypt(uint, int, int);
   static const Waypoint* lowranceusr4_find_global_waypt(uint, uint, uint, uint);
diff --git a/main.cc b/main.cc
index 6487ba60430849b06507d48e8067acabb9a9b85a..3f5a08a91c5b096b7ecc472e9f7de2677a002c81 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -55,7 +55,7 @@
 #include "src/core/usasciicodec.h"    // for UsAsciiCodec
 #include "vecs.h"                     // for Vecs
 
-static constexpr int DEBUG_LOCALE = 0;
+static constexpr bool DEBUG_LOCALE = false;
 
 #define MYNAME "main"
 // be careful not to advance argn passed the end of the list, i.e. ensure argn < qargs.size()
@@ -414,7 +414,7 @@ run(const char* prog_name)
       }
       break;
     case 's':
-      global_opts.synthesize_shortnames = 1;
+      global_opts.synthesize_shortnames = true;
       break;
     case 't':
       global_opts.objective = trkdata;
@@ -435,14 +435,14 @@ run(const char* prog_name)
     case 'S':
       switch (qargs.at(argn).size() > 2 ? qargs.at(argn).at(2).toLatin1() : '\0') {
       case 'i':
-        global_opts.smart_icons = 1;
+        global_opts.smart_icons = true;
         break;
       case 'n':
-        global_opts.smart_names = 1;
+        global_opts.smart_names = true;
         break;
       default:
-        global_opts.smart_icons = 1;
-        global_opts.smart_names = 1;
+        global_opts.smart_icons = true;
+        global_opts.smart_names = true;
         break;
       }
       break;
index 77e322e45bfd7c1a5707179833de019bdf11b5b2..de63389efe67031fd8d31612148950ab02b9d569 100644 (file)
@@ -154,4 +154,4 @@ bool CodecDevice::isSequential() const
   return true;
 }
 
-} // namespace
+} // namespace gpsbabel
index 596bc2dcb0f3bf3975ead4294080cf8a7afc6a5c..b1ef1b35a53090634a4d7dbf2bcaf6b362b7716c 100644 (file)
@@ -62,5 +62,5 @@ private:
   qint64 charbuffer_bytes_free_{charbuffer_size_};
 };
 
-} // namespace
+} // namespace gpsbabel
 #endif // SRC_CORE_CODECDEVICE_H_
diff --git a/util.cc b/util.cc
index e67b0bcaab5b5649ed0ff6e67aabe3c20c37725c..31ab466e06dd42f75ee45efb91b2d231424aeaa7 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -146,7 +146,7 @@ xrealloc(void* p, size_t s)
 FILE*
 xfopen(const char* fname, const char* type, const char* errtxt)
 {
-  int am_writing = strchr(type, 'w') != nullptr;
+  bool am_writing = strchr(type, 'w') != nullptr;
 
   if (fname == nullptr) {
     fatal("%s must have a filename specified for %s.\n",
index 640ceaba33674f48ad832c07153c85e04174d8a6..068d7db7579c9810cdcc37f93d42926ad6e49c36 100644 (file)
@@ -69,7 +69,7 @@ unsigned long
 get_crc32(const void* data, int datalen)
 {
   unsigned long crc = 0xFFFFFFFF;
-  const unsigned char* cp = static_cast<const unsigned char*>(data);
+  const auto* cp = static_cast<const unsigned char*>(data);
 
   while (cp < (static_cast<const unsigned char*>(data) + datalen)) {
     crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF];
index df02d17156fe1a70c0fc1d092320f7e906a047e8..39edfccc03e0be223abe7e50d03c5020817aa530 100644 (file)
--- a/waypt.cc
+++ b/waypt.cc
@@ -113,7 +113,7 @@ waypt_init_bounds(bounds* bounds)
   bounds->min_alt = -unknown_alt;
 }
 
-int
+bool
 waypt_bounds_valid(bounds* bounds)
 {
   /* Returns true if bb has any 'real' data in it */